<template>
  <d2-container>
    <template slot="header">
      <i class="el-icon-setting"></i>&nbsp;设置切片
    </template>
    <el-form :inline="true" :model="slice_configuration" class="demo-form-inline">
      <el-form-item label="bs_id">
        <el-input v-model="bs_id" placeholder="基站bs_id, -1 为所有基站"></el-input>
      </el-form-item>
      <br />UL Parameters
      <br />
      <el-form-item label="算法">
        <el-select v-model="slice_configuration.ul.algorithm" placeholder="algorithm">
          <el-option label="None" value="None"></el-option>
          <el-option label="Static" value="Static"></el-option>
        </el-select>&nbsp;
        <el-form-item label="切片id">
          <el-input v-model="slice_configuration.ul.slices[0].id" placeholder="1~255"></el-input>
        </el-form-item>
      </el-form-item>
      <el-form-item label=" slice_static">
        <el-input v-model="slice_configuration.ul.slices[0].static.posLow" placeholder="posLow"></el-input>
      </el-form-item>
      <el-form-item label=" slice_static">
        <el-input v-model="slice_configuration.ul.slices[0].static.posHigh" placeholder="posHigh"></el-input>
      </el-form-item>
      <br />DL Parameters
      <br />
      <el-form-item label="算法">
        <el-select v-model="slice_configuration.dl.algorithm" placeholder="algorithm">
          <el-option label="None" value="None"></el-option>
          <el-option label="Static" value="Static"></el-option>
        </el-select>&nbsp;
        <el-form-item label="切片id">
          <el-input v-model="slice_configuration.dl.slices[0].id" placeholder="1~255"></el-input>
        </el-form-item>
      </el-form-item>
      <el-form-item label=" slice_static">
        <el-input v-model="slice_configuration.dl.slices[0].static.posLow" placeholder="posLow"></el-input>
      </el-form-item>
      <el-form-item label=" slice_static">
        <el-input v-model="slice_configuration.dl.slices[0].static.posHigh" placeholder="posHigh"></el-input>
      </el-form-item>
      <br />
      <el-form-item>
        <el-button type="success" @click="onSubmit">提交</el-button>
        <el-button type="warning" @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>

<script>
import Axios from 'axios'
export default {
  name: 'page3',
  data () {
    return {
      bs_id: '',
      slice_configuration: {
        ul: {
          algorithm: '',
          slices: [
            {
              id: '',
              static: {
                posLow: '',
                posHigh: ''
              }
            }
          ]
        },
        dl: {
          algorithm: '',
          slices: [
            {
              id: '',
              static: {
                posLow: '',
                posHigh: ''
              }
            }
          ]
        }
      }
    }
  },
  methods: {
    cancel(){this.slice_configuration = {}},
    onSubmit () {
      const data = {
        ul: {},
        dl: {}
      }
      if (this.slice_configuration.ul.algorithm === 'None') {
        data.ul = {
          algorithm: 'None'
        }
      } else {
        data.ul = this.slice_configuration.ul
      }
      if (this.slice_configuration.dl.algorithm === 'None') {
        data.dl = {
          algorithm: 'None'
        }
      } else {
        data.dl = this.slice_configuration.dl
      }
      console.log(data)
      Axios({
        method: 'post',
        url: '/api/slice/enb/' + this.bs_id,
        data
      }).then(res => {
        console.log(res.data)
        if (res.data.status === 'Ok') {
          this.$message({
            message: '提交成功',
            type: 'success'
          })
        }
        this.$router.push({ path: 'slicingLists' })
      })
    },
  }
}
</script>
